<template>
  <div class="row justify-content-center">
    <div class="col-8">
      <form name="editForm" role="form" novalidate v-on:submit.prevent="save()">
        <h2 id="myapplication1App.userRole.home.createOrEditLabel" data-cy="UserRoleCreateUpdateHeading">Create or edit a UserRole</h2>
        <div>
          <div class="form-group" v-if="userRole.id">
            <label for="id">ID</label>
            <input type="text" class="form-control" id="id" name="id" v-model="userRole.id" readonly />
          </div>
          <div class="form-group">
            <label class="form-control-label" for="user-role-roleName">Role Name</label>
            <input
              type="text"
              class="form-control"
              name="roleName"
              id="user-role-roleName"
              data-cy="roleName"
              :class="{ valid: !$v.userRole.roleName.$invalid, invalid: $v.userRole.roleName.$invalid }"
              v-model="$v.userRole.roleName.$model"
              required
            />
            <div v-if="$v.userRole.roleName.$anyDirty && $v.userRole.roleName.$invalid">
              <small class="form-text text-danger" v-if="!$v.userRole.roleName.required"> This field is required. </small>
            </div>
          </div>
          <div class="form-group">
            <label for="user-role-teacher">Teacher</label>
            <select
              class="form-control"
              id="user-role-teachers"
              data-cy="teacher"
              multiple
              name="teacher"
              v-if="userRole.teachers !== undefined"
              v-model="userRole.teachers"
            >
              <option
                v-bind:value="getSelected(userRole.teachers, teacherOption)"
                v-for="teacherOption in teachers"
                :key="teacherOption.id"
              >
                {{ teacherOption.id }}
              </option>
            </select>
          </div>
          <div class="form-group">
            <label for="user-role-student">Student</label>
            <select
              class="form-control"
              id="user-role-students"
              data-cy="student"
              multiple
              name="student"
              v-if="userRole.students !== undefined"
              v-model="userRole.students"
            >
              <option
                v-bind:value="getSelected(userRole.students, studentOption)"
                v-for="studentOption in students"
                :key="studentOption.id"
              >
                {{ studentOption.id }}
              </option>
            </select>
          </div>
        </div>
        <div>
          <button type="button" id="cancel-save" data-cy="entityCreateCancelButton" class="btn btn-secondary" v-on:click="previousState()">
            <font-awesome-icon icon="ban"></font-awesome-icon>&nbsp;<span>Cancel</span>
          </button>
          <button
            type="submit"
            id="save-entity"
            data-cy="entityCreateSaveButton"
            :disabled="$v.userRole.$invalid || isSaving"
            class="btn btn-primary"
          >
            <font-awesome-icon icon="save"></font-awesome-icon>&nbsp;<span>Save</span>
          </button>
        </div>
      </form>
    </div>
  </div>
</template>
<script lang="ts" src="./user-role-update.component.ts"></script>
